package com.java110.mall.cart.smo.impl;


import com.java110.mall.cart.dao.IGoldBusinessServiceDao;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.gold.GoldBusinessDto;
import com.java110.intf.cart.IGoldBusinessInnerServiceSMO;
import com.java110.po.gold.GoldBusinessPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 购买记录内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class GoldBusinessInnerServiceSMOImpl extends BaseServiceSMO implements IGoldBusinessInnerServiceSMO {

    @Autowired
    private IGoldBusinessServiceDao goldBusinessServiceDaoImpl;


    @Override
    public int saveGoldBusiness(@RequestBody GoldBusinessPo goldBusinessPo) {
        int saveFlag = 1;
        goldBusinessServiceDaoImpl.saveGoldBusinessInfo(BeanConvertUtil.beanCovertMap(goldBusinessPo));
        return saveFlag;
    }

    @Override
    public int updateGoldBusiness(@RequestBody GoldBusinessPo goldBusinessPo) {
        int saveFlag = 1;
        goldBusinessServiceDaoImpl.updateGoldBusinessInfo(BeanConvertUtil.beanCovertMap(goldBusinessPo));
        return saveFlag;
    }

    @Override
    public int deleteGoldBusiness(@RequestBody GoldBusinessPo goldBusinessPo) {
        int saveFlag = 1;
        goldBusinessPo.setStatusCd("1");
        goldBusinessServiceDaoImpl.updateGoldBusinessInfo(BeanConvertUtil.beanCovertMap(goldBusinessPo));
        return saveFlag;
    }

    @Override
    public List<GoldBusinessDto> queryGoldBusinesss(@RequestBody GoldBusinessDto goldBusinessDto) {

        //校验是否传了 分页信息

        int page = goldBusinessDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            goldBusinessDto.setPage((page - 1) * goldBusinessDto.getRow());
        }

        List<GoldBusinessDto> goldBusinesss = BeanConvertUtil.covertBeanList(goldBusinessServiceDaoImpl.getGoldBusinessInfo(BeanConvertUtil.beanCovertMap(goldBusinessDto)), GoldBusinessDto.class);

        return goldBusinesss;
    }


    @Override
    public int queryGoldBusinesssCount(@RequestBody GoldBusinessDto goldBusinessDto) {
        return goldBusinessServiceDaoImpl.queryGoldBusinesssCount(BeanConvertUtil.beanCovertMap(goldBusinessDto));
    }

    public IGoldBusinessServiceDao getGoldBusinessServiceDaoImpl() {
        return goldBusinessServiceDaoImpl;
    }

    public void setGoldBusinessServiceDaoImpl(IGoldBusinessServiceDao goldBusinessServiceDaoImpl) {
        this.goldBusinessServiceDaoImpl = goldBusinessServiceDaoImpl;
    }
}
